package com.skyline.jfs.namespace.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.skyline.jfs.common.config.Config;
import com.skyline.jfs.namespace.dao.JFSFileDao;
import com.skyline.jfs.namespace.mapper.JFSFileMapper;
import com.skyline.jfs.namespace.model.JFSFile;
@Component("jfsFileDao")
public class JFSFileDaoImpl implements JFSFileDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<JFSFile> findAllSubFiles(Long dirID) {
		String sql=Config.getSql("JFSFileDao.findAllSubFiles");
		return jdbcTemplate.query(sql,JFSFileMapper.getMapper(), dirID);
	}

	@Override
	public List<JFSFile> findAllSubFiles(String dir) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void  insertFile(Long parent,String name,String path,Long size,Integer replicNum,Integer permission){
		String sql=Config.getSql("JFSFileDao.insertFile");
		jdbcTemplate.update(sql,parent, name, path, size, replicNum, permission);
	}
	
	public JFSFile findFileByID(Long id){
		return null;
	}
	
	public JFSFile findFileByDir(String dir){
		
		String sql=Config.getSql("JFSFileDao.findFileByDir");
		List<JFSFile> files=jdbcTemplate.query(sql, JFSFileMapper.getMapper(),dir);
		if(files==null||files.size()==0){
			return null;
		}
		else{
			return files.get(0);
		}
	}


}
